#include <iostream>

using namespace std;
/* run this program using the console pauser or add your own getch, system("pause") or input loop */
void quick_sort(int a[],int left,int right);
void print_d(int a[]);
int main() {
	int a_data[] = {3,8,4,10,6,7,2,5,9,1};
	quick_sort(a_data,0,9);
	
	return 0;
}


//void quick_sort(int a[],int left,int right)
void quick_sort(int a[],int left,int right)
{
	int index_p = (left+right)/2;
	int pivot = a[index_p];
	int i = left;
	int j = right;
	
	do{
		while(a[i]<pivot ){
			i++;
		}
		while(a[j] >pivot){
			j--;
		}
		if(i<=j)
		{
			int tmp = a[i];
			a[i]= a[j];
			a[j] = tmp;
			i++;
			j--;
		}
		
	}while(i<=j);
	
	cout<<i<<"-i		j-"<<j<<endl;
	print_d(a);
	
	if(left<j)
	quick_sort(a,left,j);
	if(i< right )
	quick_sort(a,i,right);
}


void print_d(int a[],int left,int right)
{
	for(int i=0;i<sizeof(a)/sizeof(a[0]);i++){
		cout << a[i]<<" ";
		//TODO
	}
	cout<<endl;
}
